package com.example.blog;

import com.example.blog.Common.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Set;

public class RedisController {
    @Autowired
    private RedisTemplate redisTemplate;
    @GetMapping(value = "/getHour")
    public Set getHour(){
        //ZREVANGE
        long  hour=System.currentTimeMillis()/(1000*60*60);
        Set<ZSetOperations.TypedTuple<Integer>>rang=this.redisTemplate.opsForZSet().reverseRangeByScore(Constants.HOUR_KEY+hour,0,30);
        return rang;
    }
    @GetMapping(value = "/getDay")
    public Set getDay(){
        //ZREVANGE
        Set<ZSetOperations.TypedTuple<Integer>>rang=this.redisTemplate.opsForZSet().reverseRangeByScore(Constants.DAY_KEY,0,30);
        return rang;
    }
    @GetMapping(value = "/getWeek")
    public Set getWeek(){
        //ZREVANGE
        Set<ZSetOperations.TypedTuple<Integer>>rang=this.redisTemplate.opsForZSet().reverseRangeByScore(Constants.WEEK_KEY,0,30);
        return rang;
    }
    @GetMapping(value = "/getMonth")
    public Set getMonth(){
        //ZREVANGE
        Set<ZSetOperations.TypedTuple<Integer>>rang=this.redisTemplate.opsForZSet().reverseRangeByScore(Constants.MONTH_KEY,0,30);
        return rang;
    }
}
